package com.ruibang.glass.etl.handler.sl;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.SlStationMes2Detail;
import com.ruibang.glass.etl.entity.SlStationMes3Detail;
import com.ruibang.glass.etl.mapper.SlStationMes2DetailMapper;
import com.ruibang.glass.etl.mapper.SlStationMes3DetailMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "sl")
public class SLStationMes3DetailBinlogEventHandler implements IBinlogEventHandler<SlStationMes3Detail> {

    @Autowired
    private SlStationMes3DetailMapper slStationMes3DetailMapper;

    @Override
    public void onInsert(BinlogEvent<SlStationMes3Detail> event) {
        if(1 > slStationMes3DetailMapper.insert(event.getData())){
            System.out.println("sl_station_mes3_detail_2024 插入数据失败:" + event.getData());
        }else
            System.out.println("sl_station_mes3_detail_2024 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<SlStationMes3Detail> event)  {
        if(1 > slStationMes3DetailMapper.updateById(event.getData())){
            System.out.println("sl_station_mes3_detail_2024 修改数据失败:" + event.getData());
            onInsert(event);
        }else
            System.out.println("sl_station_mes3_detail_2024 更新数据成功");
    }

    @Override
    public void onDelete(BinlogEvent<SlStationMes3Detail> event) {
        if(1 > slStationMes3DetailMapper.deleteById(event.getData())){
            System.out.println("sl_station_mes3_detail_2024 删除数据失败:" + event.getData());
        }else
            System.out.println("sl_station_mes3_detail_2024 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("cold1_bc2mes") && table.startsWith("sl_station_mes3_detail");
    }
}
